package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingProjectController
 * @Author lifuyun
 * @Date 2024-08-23
 */
@RestController
@RequestMapping("/nursing_project")
@Slf4j
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页查询护理项目列表
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称") String name,
            @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        log.info("分页查询护理项目列表，参数：名称={}，状态={}，页码={}，每页数量={}", name, status, pageNum, pageSize);

        //调用业务层分页查询
        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(name, status, pageNum, pageSize);

        return success(nursingProjectPageInfo);
    }

    /**
     * 新增护理项目
     *
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    @ApiImplicitParam(name = "nursingProjectDto", value = "护理项目数据传输对象", required = true)
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto) {
        log.info("处理新增护理项目请求，请求参数：{}", nursingProjectDto);
        nursingProjectService.add(nursingProjectDto);
        return success();

    }

    /**
     * 根据ID查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getById(
            @ApiParam(value = "护理项目ID", required = true)
            @PathVariable("id") Long id) {
        log.info("处理根据id查询护理项目的请求，用与修改护理项目时回显数据，请求参数：{}", id);
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }

    /**
     * 编辑护理项目
     *
     * @param nursingProject
     * @return
     */
    @PutMapping
    @ApiOperation("编辑护理项目")
    @ApiImplicitParam(name = "nursingProject", value = "护理项目数据传输对象", required = true)
    public ResponseResult<NursingProjectVo> updateNursingProject(@RequestBody NursingProject nursingProject) {
        log.info("处理编辑护理项目请求，请求参数：{}", nursingProject);
        nursingProjectService.updateNursingProject(nursingProject);
        return success();
    }

    /**
     * 护理项目启用禁用
     *
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("护理项目启用禁用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "护理项目ID", required = true),
            @ApiImplicitParam(name = "status", value = "状态：0-禁用，1-启用", required = true)})
    public ResponseResult<NursingProjectVo> updateNursingProjectStatus(
            @PathVariable long id,
            @PathVariable int status
    ) {
        log.info("处理护理项目启用禁用请求，请求参数：id={}，status={}", id, status);
        nursingProjectService.updateNursingProjectStatus(id, status);
        return success();
    }

    /**
     * 根据id删除护理项目
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理项目")
    public ResponseResult<NursingProjectVo> deleteNursingProject(
            @ApiParam(value = "护理项目ID", required = true) @PathVariable long id) {
        log.info("处理根据id删除护理项目请求，请求参数：id={}", id);
        nursingProjectService.deleteNursingProject(id);
        return success();
    }

    /**
     * 查询所有护理项目
     *
     * @return
     */
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> getAllNursingProject() {
        log.info("查询所有护理项目");
        List<NursingProjectVo> nursingProjectVoList = nursingProjectService.getAllNursingProject();
        return success(nursingProjectVoList);

    }
}
